"""
    @Author  ：思念 
    @File    ：1.进程基础.py
    @Date    ：2025/3/7 10:04 
"""

from multiprocessing import Process
import time
import os

def work_1(name):
    for i in range(1,5):
        print(f"任务一：{name} is running:{i}")
        time.sleep(1)
    print(f"任务一子进程编号：{os.getpid()}")
def work_2(name):
    for i in range(1,5):
        print(f"任务二：{name} is running:{i}")
        print(f"子进程编号：{os.getpid()}")
        time.sleep(1)
    print(f"任务二子进程编号：{os.getpid()}")
    print(f"主进程编号：{os.getppid()}")

if __name__ == '__main__':
    p1 = Process(target=work_1,args=("张三",))
    p2 = Process(target=work_2, args=("李四",))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    print("主进程结束")
    # 获取进程编号
    print(f"主进程编号：{os.getpid()}")


